﻿/**
* @author	:	com.nickro
* 
* @USAGE	:	库中loading链接此类，loading内的文本名为"percentText"; 
				当loading需要根据percent播放帧时，可监听LoadEvent.PROGRESS事件来执行。
*
*/

package org.nickro.project.load{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	
	import org.nickro.project.events.LoadEvent;
	public class ProgressBar extends MovieClip
	{
		var total:Number = 0;
		var percent:Number = 0;
		public function ProgressBar()
		{
			trace(this);
			super();
			trace(this.parent);
			total = this.parent.loaderInfo.bytesTotal;
			this.addEventListener(Event.ENTER_FRAME,onLoading);
		}
		
		private function onLoading(e:Event):void
		{
			var loaded:Number = this.parent.loaderInfo.bytesLoaded;
			percent = int((loaded / total) * 100);
			iLabel_txt.text = String(percent);
			if(percent == 100)
			{
				this.removeEventListener(Event.ENTER_FRAME,onLoading);
				dispatchEvent(new LoadEvent(LoadEvent.COMPLETE,percent));
			}
			dispatchEvent(new LoadEvent(LoadEvent.PROGRESS,percent));
		}
		
	}
}